/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon
 												
Class							:				SupplySoftCondition
 
Function						: 				Provides a class for holding a supply 
												condition 
****************************************************************************/
package planninglanguage.softconditions;

import base.WargusGameState;
import base.WargusPlayer;

public class SupplySoftCondition extends SoftCondition {
	int m_minSupply;
	public SupplySoftCondition(int a_minSupply)
	{
		m_minSupply = a_minSupply;
	}
	public String toString(int tabs)
	{
		String n = super.toString(tabs);
		n = n + "Min Supply is:" + m_minSupply;
		return n;
	}
	public float test(WargusGameState a_gameState)
	{
//		System.out.println("SupplyCondition: test( supply = " + m_minSupply + ")");	
		
		WargusPlayer p = a_gameState.getPlayer();
		
		if (p!=null) {
			if (p.getFood() - p.getDemand() > m_minSupply) {
				return 1.0f;
			} else {
				int progress = (p.getFood() - p.getDemand());
				if (progress<0) progress=0;
				
				return ((float)progress)/((float)m_minSupply);
			}					
		}		
		return 0.0f;	
	}

}
